using FireStarterModeller.BO;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    [TestFixture]
    public class TestUIColumnInfo : TestBase
    {
        [SetUp]
        public override void SetupTest()
        {
            //Runs every time that any testmethod is executed
            base.SetupTest();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
        }

        [TearDown]
        public override void TearDownTest()
        {
            //runs every time any testmethod is complete
            base.TearDownTest();
        }

        [Test]
        public void Test_InsertNewUIColumnInfo_Invalid()
        {
            //---------------Set up test pack-------------------
            UIColumn uiColumn = new UIColumn();

            //---------------Assert Precondition----------------
            Assert.IsTrue(uiColumn.Status.IsNew);

            //---------------Execute Test ----------------------
            try
            {
                uiColumn.Save();
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (BusObjectInAnInvalidStateException ex)
            {
                StringAssert.Contains("Property' is a compulsory field and has no value", ex.Message);
            }
            Assert.IsTrue(uiColumn.Status.IsNew);
        }

        [Test]
        public void Test_InsertNewUIColumnInfo()
        {
            //---------------Set up test pack-------------------
            UIColumn uiColumn = TestUtils.CreateUnsavedValidUIColumnInfo();

            //---------------Assert Precondition----------------
            Assert.IsTrue(uiColumn.Status.IsNew);

            //---------------Execute Test ----------------------
            uiColumn.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(uiColumn.Status.IsNew);
        }

        [Test]
        public void Test_DeleteUIColumnInfo()
        {
            //---------------Set up test pack-------------------
            UIColumn uiColumn = TestUtils.CreateSavedUIColumnInfo();

            //---------------Assert Precondition----------------
            Assert.IsFalse(uiColumn.Status.IsNew);
            string message;
            Assert.IsTrue(uiColumn.IsDeletable(out message));

            //---------------Execute Test ----------------------
            uiColumn.MarkForDelete();
            uiColumn.Save();

            //---------------Test Result -----------------------  
            Assert.IsTrue(uiColumn.Status.IsNew);
            Assert.IsTrue(uiColumn.Status.IsDeleted);
        }

        [Test]
        public void Test_UpdateUIColumnInfo()
        {
            //---------------Set up test pack-------------------
            UIColumn uiColumn = TestUtils.CreateSavedUIColumnInfo();

            //---------------Assert Precondition----------------
            Assert.IsFalse(uiColumn.Status.IsNew);
            string message;
            Assert.IsTrue(uiColumn.IsEditable(out message));

            //---------------Execute Test ----------------------
            TestUtils.UpdateUIColumnInfoWithValidData(uiColumn);

            //---------------Test Result -----------------------
            Assert.IsFalse(uiColumn.Status.IsNew);
        }
    }
}